//
// Created by gaodapeng on 2020/4/19.
//

#include <stdio.h>
#include "stus.h"
#include <string.h>

struct Book {
    char title[30];
    char author[10];
    int book_id;
} /*book = {"书名", "作者", 123554}*/;

void strus1() {
    struct Book book1;
    struct Book book2;

    strcpy(book1.title, "书1");
    strcpy(book1.author, "cr");
    book1.book_id = 12345678;

    strcpy(book2.title, "书2");
    strcpy(book2.author, "xr");
    book2.book_id = 94034902;

    printf("%s %s %d\n", book1.title, book1.author, book1.book_id);
    printf("%s %s %d\n", book2.title, book2.author, book2.book_id);

    struct Book *p_book = &book1;
    //指针方式访问的话，引用符号不一样
    printf("%s %s %d\n", p_book->title, p_book->author, p_book->book_id);
    printf("%s %s %d\n", (*p_book).title, (*p_book).author, (*p_book).book_id);

}

/**
 * 共用体
 */
union Data {
    int i;
    float j;
    char c[20];
};

void strus2() {
    union Data data;
    data.i = 10;
    data.j = 12.889f;
    strcpy(data.c, "r");
    printf("sizeof(data) = %lu\n", sizeof(data));
    printf("%d %f %s\n", data.i, data.j, data.c);

}